package com.Hiram.Controller;

import com.Hiram.Assistant.YiLiaoChatAssistant;
import com.Hiram.DTO.ChatSessionDTO;
import com.Hiram.DTO.UserChatSessionSummaryDTO;
import com.Hiram.Service.ServiceImpl.ChatMessagesService;
import com.Hiram.bean.ChatForm;
import com.Hiram.bean.ChatMessages;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;


@Tag(name = "医疗机器人")
@RestController
@RequestMapping("/yiliao")
public class YiLiaoController {

    @Autowired
    private YiLiaoChatAssistant assistant;

    @PostMapping(value = "/chat", produces = "text/stream;charset=utf-8")
    public Flux<String> chat(@RequestBody ChatForm chatForm) {
        return assistant.chat(chatForm.getMemoryId(), chatForm.getMessage());
    }


    @Autowired
    private ChatMessagesService chatMessagesService;

    // 查询用户的所有聊天记录
    @GetMapping("/user/{userId}")
    public List<UserChatSessionSummaryDTO>  getUserChatRecords(@PathVariable("userId") Integer userId) {
        return chatMessagesService.findAllByUserId(userId);
    }

    // 查询特定会话的所有记录
    @GetMapping("/memory/{memoryId}")
    public ChatSessionDTO getMemoryChatRecords(@PathVariable("memoryId") Integer memoryId) {

        return chatMessagesService.findAllByMemoryId(memoryId);
    }


}
